package com.sidianzhong.sdz.service.impl;
import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;

/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebZequipmentitemgroupServiceImpl implements WebZequipmentitemgroupService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebZequipmentitemgroupServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebZequipmentitemgroupMapper webZequipmentitemgroupMapper;


    @Override
    public WebZequipmentitemgroup create(WebZequipmentitemgroup item) {

         webZequipmentitemgroupMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webZequipmentitemgroupMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebZequipmentitemgroup item) {

        return webZequipmentitemgroupMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebZequipmentitemgroup get(Integer id) {
        return webZequipmentitemgroupMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<WebZequipmentitemgroup> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,WebZequipmentitemgroup item){

        WebZequipmentitemgroupExample  example = new WebZequipmentitemgroupExample();
        WebZequipmentitemgroupExample.Criteria criteria = example.createCriteria();
        if(item.getRoomname() != null ){
            criteria.andRoomnameEqualTo(item.getRoomname());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getOwnkey() != null ){
            criteria.andOwnkeyEqualTo(item.getOwnkey());
        }
        if(item.getOwntype() != null ){
            criteria.andOwntypeEqualTo(item.getOwntype());
        }
        if(item.getOwnname() != null ){
            criteria.andOwnnameEqualTo(item.getOwnname());
        }
        if(item.getAlarmup() != null ){
            criteria.andAlarmupEqualTo(item.getAlarmup());
        }
        if(item.getAlarmdown() != null ){
            criteria.andAlarmdownEqualTo(item.getAlarmdown());
        }
        if(item.getStatus() != null ){
            criteria.andStatusEqualTo(item.getStatus());
        }
        if(item.getIfalarm() != null ){
            criteria.andIfalarmEqualTo(item.getIfalarm());
        }
        if(item.getIfkey() != null ){
            criteria.andIfkeyEqualTo(item.getIfkey());
        }
        if(item.getShowform() != null ){
            criteria.andShowformEqualTo(item.getShowform());
        }
        if(item.getValuesize() != null ){
            criteria.andValuesizeEqualTo(item.getValuesize());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebZequipmentitemgroup> list = this.webZequipmentitemgroupMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public List<WebZequipmentitemgroup> getList(Integer pageNum, Integer pageSize, String sortItem, String sortOrder, WebZequipmentitemgroup item) {
        WebZequipmentitemgroupExample  example = new WebZequipmentitemgroupExample();
        WebZequipmentitemgroupExample.Criteria criteria = example.createCriteria();
        if(item.getRoomname() != null ){
            criteria.andRoomnameEqualTo(item.getRoomname());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getOwnkey() != null ){
            criteria.andOwnkeyEqualTo(item.getOwnkey());
        }
        if(item.getOwntype() != null ){
            criteria.andOwntypeEqualTo(item.getOwntype());
        }
        if(item.getOwnname() != null ){
            criteria.andOwnnameEqualTo(item.getOwnname());
        }
        if(item.getAlarmup() != null ){
            criteria.andAlarmupEqualTo(item.getAlarmup());
        }
        if(item.getAlarmdown() != null ){
            criteria.andAlarmdownEqualTo(item.getAlarmdown());
        }
        if(item.getStatus() != null ){
            criteria.andStatusEqualTo(item.getStatus());
        }
        if(item.getIfalarm() != null ){
            criteria.andIfalarmEqualTo(item.getIfalarm());
        }
        if(item.getIfkey() != null ){
            criteria.andIfkeyEqualTo(item.getIfkey());
        }
        if(item.getShowform() != null ){
            criteria.andShowformEqualTo(item.getShowform());
        }
        if(item.getValuesize() != null ){
            criteria.andValuesizeEqualTo(item.getValuesize());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);

        List< WebZequipmentitemgroup> list = this.webZequipmentitemgroupMapper.selectByExample(example);
        return list;
    }

}
